package com.tailyou.hms.firstapp.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.tailyou.hms.firstapp.R;
import com.tailyou.hms.firstapp.bean.MLBean;
import com.tailyou.hms.firstapp.bean.RVBean;

import java.util.List;

public abstract class List2Adapter extends RecyclerView.Adapter<List2Adapter.RVHolder> {

    private List<MLBean.DataDTO.ListDTO.RoomlistDTO> datas;

    public List2Adapter(List<MLBean.DataDTO.ListDTO.RoomlistDTO> datas) {
        this.datas = datas;
    }

    @NonNull
    @Override
    public List2Adapter.RVHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout_list2, parent, false);
        return new RVHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull List2Adapter.RVHolder holder, int position) {
        holder.tvName.setText(datas.get(position).getName());
        holder.itemView.setOnClickListener(v -> clickItem(position));
    }

    public abstract void clickItem(int position);

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class RVHolder extends RecyclerView.ViewHolder {
        private TextView tvName;
        private ImageView ivPic;

        public RVHolder(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tvName);
            ivPic = itemView.findViewById(R.id.ivPic);
        }
    }
}
